import React from 'react';
import { connect } from 'dva';
import echarts from 'echarts/lib/echarts';

// function AutomaticEcharts ({dataArr,xData,dataArr1,dataArr2,dataArr3,dataArr4,dataArr5,dataArr6,dataArr7,data,dispatch}){
class Variance extends React.Component {
    constructor(props){
        super(props);
        this.state = {
        
        };

    }

    
    componentDidMount() {
        // 基于准备好的dom，初始化echarts实例
        const { dataArr,dataArr1,dataArr2,dataArr3,dataArr4,dataArr5,dataArr6,dataArr7 } = this.props;
        
        function Fun_variance(numbers) {  
            var mean = 0;  
            var sum = 0;  
            for(var i=0;i<numbers.length;i++){  
                sum += numbers[i];  
            }  
            mean = sum / numbers.length;  
            sum = 0;  
            for(var i=0;i<numbers.length;i++){  
                sum += Math.pow(numbers[i] - mean , 2);  
            }  
            return sum / numbers.length;  
        };
       var variance = Fun_variance(dataArr);
       var variance1 = Fun_variance(dataArr1);
       var variance2 = Fun_variance(dataArr2);
       var variance3 = Fun_variance(dataArr3);
       var variance4 = Fun_variance(dataArr4);
       var variance5= Fun_variance(dataArr5);
       var variance6 = Fun_variance(dataArr6);
       var variance7 = Fun_variance(dataArr7);
       

        var myChart = echarts.init(document.getElementById('main'));
 
      
        // 指定图表的配置项和数据
       
        var  option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            toolbox: {
                feature: {
                    dataView: {show: true, readOnly: false},
               
                    restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
          
            xAxis: [
                {
                    type: 'category',
                    data: ['曲线','曲线1','曲线2','曲线3','曲线4','曲线5','曲线6','曲线7',],
                    axisPointer: {
                        type: 'shadow'
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: '数值',
        
                    axisLabel: {
                        formatter: '{value} '
                    }
                }
            ],
            series: [{
                symbolSize: 20,
                data: [
                    [0, variance],
                    [1,variance1],
                    [2, variance2],
                    [3, variance3],
                    [4, variance4],
                    [5, variance5],
                    [6,variance6],
                    [7,variance7],
                  
                ],
                type: 'line'
            }]
        };
      
        myChart.setOption(option);
    
         
     
    }
  
    
    render() {
        return (
            <div>

                <div id="main" style={{ width: 1600, height: 700 }}></div>

            </div>

        );
    }
}
// export default LineMarkerEcharts;
export default connect(({ echart }) => ({ ...echart }))(Variance)